<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class EventResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id ?? '',
            'event_number' => $this->event_number ?? '',
            'type' => $this->type ?? '',
            'customer_name' => $this->customer->name ?? '',
            'customer_user_name' => $this->customer->user->name ?? '',
            'contact_phone' => $this->customer->user->phone ?? '',
            'address' => $this->address,
            'device_name' => $this->product->name ?? '',
            'status' => $this->status ?? '',
            'created_type' => $this->created_type ?? '',
            'create_time' => Carbon::parse($this->create_time)->toDateTimeString()
        ];
        return parent::toArray($request);
    }
}
